/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package session;

import entity.Type;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Mély
 */
@Stateless
public class TypeFacade extends AbstractFacade<Type> implements TypeFacadeLocal {
    @PersistenceContext(unitName = "WebSgbd-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public TypeFacade() {
        super(Type.class);
    }
    
    @Override
    public Type findByType(String type) {
        String sql = "SELECT Object(t) "
                + "FROM Type t "
                + "WHERE t.typeBDD LIKE :type";
        Query query = em.createQuery(sql);
        query.setParameter("type", "%" + type + "%");
        
        return (Type)query.getResultList().get(0);
    }
    
}
